<?php
/**
 *
 */
abstract class panel__model__commands {

	static public function getCommand( $_id_, array $_ = array() ) {

		$R = self::getCommands( array_merge( array("where_id" => $_id_), $_ ) );

		$R = end($R);

		if( !$R && isset_or($_["exception_if_not_exists"]) ) {

			throw new panel__e__not_found(
				"Command '{$_id_}' is not found",
				$_["exception_if_not_exists"]
			);

		}	# if

		return $R;

	}	# Function

	static public function getCommands( array $_ = array() ) {

		$Q = p()->db()->select()
		->setFrom("runcom.commands", "c")
		->addSelectEFields("c.id", "COMMAND")
		->addSelect("c.command")
		->addSelect("c.description")
		->setOrderBy("c.description")
		;

		if( isset_or($_["where_id"]) ) {

			$Q
			->addWhere("c.id", "=", $_["where_id"])
			->setLimit(1)
			;

		}	# if

		if( isset_or($_["where_vendor_id"]) ) {

			$Q
			->addWhere("c.vendor_id", "=", $_["where_vendor_id"])
			;

		}	# if

		$R = $Q->execute();

		return $R;

	}	# Function

}	# Class

/* EOF */